package maurice.controller;

import wiiusej.WiiUseApiManager;
import wiiusej.Wiimote;
import maurice.controller.event.*;

public class WiiControllerTest implements ControllerListener{
	private Wiimote[] wiimotes;
	private Controller wii1;
	private Controller wii2;
	
	
	public WiiControllerTest(){
		wiimotes = WiiUseApiManager.getWiimotes(2, true);
		wii1 = new WiiController(wiimotes[0]);
		wii2 = new WiiController(wiimotes[1]);
		
		wii1.addControllerListener(this);
		wii2.addControllerListener(this);
		
		wii1.start();
		wii2.start();
	}

	@Override
	public void movementConfirmed(MovementConfirmedEvent event) {
		if (event.getSource() == wii1){
			System.out.println("Wiimote 1 : " + event.getDirection());
		}
		
		if (event.getSource() == wii2){
			System.out.println("Wiimote 2 : " + event.getDirection());
			if (event.getDirection() == Direction.DOWN){
				wii1.interrupt();
				wii2.interrupt();
				WiiUseApiManager.shutdown();
			}
		}
		
	}
	
	public static void main(String[] args){
		WiiControllerTest test = new WiiControllerTest();

	}

}
